package com.itheima.service.activeMQ;

import com.itheima.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MessageServiceActiveMQImpl implements MessageService {

    //注入jmstemplate对象
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;
    @Override
    public void sendMessage(String id) {
        //将消息的id存入集合
        jmsMessagingTemplate.convertAndSend("order.queue.id",id);
    }
    @Override
    public String doMessage(String id) {
        //队列的特点先进先出，所以我们每次拿到集合中第一个消息进行处理
        System.out.println("消息已被处理："+id);
        jmsMessagingTemplate.receiveAndConvert("order.queue.id",String.class);
        return id;

    }
}
